/**
 * @author LinYiSong
 */
 var $$ = jQuery .noConflict();  
$$(function(){
	CKEDITOR.replace('remarks');
	refreshProCode();
	//表单验证
    $$('.form').validate({
        rules: {
            numbers: {
                required: true,
                digits:true
            },
            realPrice: {
                required: true,
                digits:true
            }
        },
        messages: {
            numbers: {
                required: '产品销售数量不能为空',
                digits:'销售数量必须为数字'
            },
            realPrice: {
                required: '产品实际销售价格不能为空',
                digits:'产品实际销售价格必须为数字'
            }
        }
    });
    /* 设置默认属性 */
    $$.validator.setDefaults({
        submitHandler: function(form){
            form.submit();
        }
    });
});

/**
 * DWR根据type异步获取产品
 */
function refreshProCode(){
	var type=$$("#proType").val();
	ProductServImpl.getProductNamebyType(type,populateCode);
}

function populateCode(list){
	DWRUtil.removeAllOptions("proCode");
	DWRUtil.addOptions("proCode", list);
	refreshName();
}

function refreshName(){
	var code=$$("#proCode").val();
	ProductServImpl.selectByCode(code,populateName);
}

function populateName(product){
	var name= product.name;
	$$("#proName").html(name);
}